import 'package:flutter/material.dart';
import 'package:net/page/rank_tab_page.dart';
import 'package:net/utils/view_util.dart';
import 'package:net/widget/h_tab.dart';
import 'package:net/widget/loading_container.dart';

///排行
class RankingPage extends StatefulWidget {
  @override
  _RankingPageState createState() => _RankingPageState();
}

class _RankingPageState extends State<RankingPage>
    with TickerProviderStateMixin {
  static const tabs = [
    {'key': 'like', 'name': '最热'},
    {'key': 'pubdate', 'name': '最新'},
    {'key': 'favorite', 'name': '收藏'},
  ];
  bool _isLoading = false;
  TabController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LoadingContainer(
        child: Padding(
          padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
          child: Column(
            children: [_tabBar(), _conTent()],
          ),
        ),
        isLoading: _isLoading,
      ),
    );
  }

  _tabBar() {
    return Container(
      alignment: Alignment.center,
      width: double.infinity,
      decoration: bottomBoxShadow(context),
      child: HTab(
        tabs: tabs
            .map<Tab>((tab) => Tab(
                  text: tab['name'],
                ))
            .toList(),
        fontSize: 16,
        borderWidth: 3,
        // insets: 20,
        unselectedLabelColor: Colors.black54,
        controller: _controller,
      ),
    );
  }

  _conTent() {
    return Flexible(
        child: TabBarView(
      controller: _controller,
      children: tabs.map((tab) {
        return Container(
          child: RankingTabPage(
            sort: tab['key'],
          ),
        );
      }).toList(),
    ));
  }
}
